# -*- coding: utf-8 -*-

import parse
from behave import given, when, then, register_type
from selenium import webdriver
from pages.search_page import SearchPage, SearchResultsPage

# -- TYPE CONVERTER: For a simple, positive integer number.
@parse.with_pattern(r"\d+")
def parse_number(text):
    return int(text)

# -- REGISTER TYPE-CONVERTER: With behave
register_type(Number=parse_number)

@given('I open website')
def step_impl(context):
    context.search_page = SearchPage(context.browser)

@when('we visit search page')
def step_impl(context):
    context.search_page.open()

@when('we type "{text}"')
def step_impl(context, text):
    context.search_page.search(text)

@then('we will find "{count:Number}" results')
def step_impl(context, count):
    context.search_results_page = SearchResultsPage(context.browser)
    assert context.search_results_page.results_count() == count
